fixed a bunch of bugs