refactor of code, and avoidance of repetition