fixed a couple of potential bugs