Bad if statement bug