optimize hacks queries