refactoring to be usable by controller