reorder if-else for better organization