separate work from error handling, into two fns