fixing logic issue