change last check statement to if-else