Minor cleanup and error handling