A number of fixes and cleanup