major code refactor to support unit tests

Also:
 * 100 unit tests in new test-btcr.py
 * test wallet files included in test-wallets/
 * additional performance improvements: faster sorting with AnchoredTokens, remove speed penalties for some features if not used in a particular run, more local aliases for globals, avoid len where possible