Major refactoring as preparation for releasing.