move logic for handling pocket query out of main()