Fixed bug and expanded test coverage.