fixed a logic problem