refactored to respond to JSON