client end was being called before the query finished