Adds improved error handling