refactored some functions to a helper class