Improve before_where and before_order_by