Logic fix and more tests.