Minor changes to improve error handling