Errors moved to a separate file. Some error handling.