Refactor into classes. Not finished.