optimize code, remove extra conditions