CS/doc fixes and code cleanup

Supersedes #549.