More cleanup and bug fixes