Fix a couple of minor logic problems