Re-factor update_query_record, made new helper function find_min_expire and use it within this method