working refactor