Fix bug and increase test coverage.