Updated code - passes unit tests.