Changed the chain of if statements to else-if