spa refactor