Added saving, refactored design, added tests.