Refactor into smaller parts