Fix queries and make sure we have a session