Converted classes from anonymous to inner
added sanity check
unified QueryHAndler
made db more restrictive