Found and fixed a bunch of bugs