added key schema support to complex queries, fixed and added tests