major code refactor to support unit tests

Also:
 * 100 unit tests in new test-btcr.py
 * wallet test files included in test-wallets/
 * avoid len where possible or use local version
 * minor bug fixes