made query a little more robust and added a simple tesr