Reorganize some legacy code and add a minimal documentation.