added direct query support, fixed tests