lots more fixes and cleanups