dry again, refactor error handling