Fix a couple of potential bugs