Add RPC call sethdseed. Clean up locking. Refactoring.