Started dynamic query building. All broken by now.