Fixed logic problem