applying tango's patches (partly)