Fixed a bunch of annoying bugs. Mostly feels like hacks though.