style tweaks and refactoring as per comments from @jsha on pull request #256