Reapplys commits from c940bae94dc9133e0fac9ff72aca679490a8b14e to bf4e73855bb8d450e70884c13ff953973cb6463d for the valid parts