logical bug in the if statement - fixed