Change sys.exit to return because now we move query into function