fixed a few potential bugs