add better handling for input in AJAX