rubocop cleanup (still a few long methods)

Many refactorings, largely to reduce method size & complexity.

Also incorporates a fix for #42, only needed in one place now.