Some fixes and cleanups