Remove useless code. Change order in if statements.