Tightened where validation
Major refactor. SQL generation now takes much heftier input but is much more flexible