functioning refactor