Valero posts smaller loss than feared as demand rebounds