Big refactor of existing code.