REL-1596: Fixed bugs as found by Andy and modified unit tests to test new features.