fixed a couple of bugs

Description in header comments