refactoring and tests for wormhole module.