Refactored code, added tests, added graphs