fixed a variety of bugs