refactor controller to respond to html/js