Refactored controller to respond to JSON