Restructuring and initial javascript for ajax.