refactoring to re-use code