cleaner & more correct implementation of where_sql