Got the logic working. Wrote some tests.