Fixed a bunch of bugs from recent changes