optimize conditional statement