Moved error handling to separate file.