fixing errors with error handling