Improved design, added tests.