Code cleanup

Identical to #962, but pointed at develop branch.