Refactoring to respond to JSON