Made queries into database-agnostic methods
Added stats JSON
AJAX/XHR handler for graph stats