fixed a lot of bugs I introduced yesterday