Lots of fixes for bugs (I'm an idiot)