refactor to avoid code duplicity