rewrote again to use hash

make the query a hash to save on processing it and simplify the code
for reading