Lots more fixes and cleanup