fixing a logic bug