Move error handling method into separate file