Reducing unnecessary if else statement