fixed the logic bug