refactor into pieces