refactored from old repo