Fixed bug in code and tests.