Wholesale changes (yes, lazy). Now with added tests.