minor refactorings

See the commit log for a step by step explanation of this PR