optimization: reduce number od CASes