Add some cleanup and bug fixes