Fixes to where clause generation