Improve code style

Variable definition in if should be avoided.