Vairous fixes
Integrate upstream changes