Much refactoring.

Changing things to remove side-effects and make methods that can be static, static.
Adds naive page detection support.
Removes unused code.
Removes unused code.
Cleaning up a bit.
Make page detection less credulous.