pull out core engin from the query method
merge with sam version
Merge pull request #11 from HaoranHuang/develop

Merged with sam's version