fix logic problems