Refactor AJAX module