Issue 120

Fix #120 and adds some refactor in query method for more modular style.