Refactored to produce non-hierarchical json responses; tests updated