Move more functionality from sinatra to javascript