Refactor into classes (partial 2)