Misc Bug Fixes and Tidying Up