Transformed to module, added tests.