refactor square