A bit of refactoring to support editing items. Improved unit tests.