fixed an issue with WHERE elements not beeing properly added to query