added ajax response, cleaned code