Fixed a logic bug