Lots of bug fixes and stuff