improved check on ajax call