Refactored code into module, added some tests, added graphs