bug fix for logic