refactor query

closes #63