Minor cleanup and improved error messages