Moved code to module, added tests