cleaned up if-else block