fix a couple of potential bugs