Logic error fixed