Big refactoring around this class.