Refactor and comment check and prune routine to improve readability.

Also get rid of some duplication.
Hopefully this should make the code more clean and intelligible, so
less error prone.
Add configure options to prune mode, enforcing sane default values.