Extracted code into module; added tests