Make the thing testable and add some tests