finished working refactor