Changed AJAX to use api

Also minor deletions of db and handlers code