refactored to move shared code to BitCore