ending refactor