move save_query and read_last_query earlier in the file