fix logic problem