almost finish the refactor