Fixed logic in if statement