Creates a cleanup script for oa issue #311.

Also includes some minor cleanup here and there.