Add more edge case tests. Fix bug in implementation. All tests passing.