isolate error handling to separate functions