fixing logic errors