fix logic errors