logic bug fix