fix logic issues