Fixed logic bug