Refactor query func
Merge pull request #3 from hainp/master

Refactor query func