Manually bringing in upstream changes + a few tweaks