fixed nested else statements
simplified code