Document Type Query Builder

fix #33, #76, #110

cleaned up version of #110 by @ivan1986

unless somebody complains i will merge this one tonight.