Misc fixes changes cherry picked from MQTT branch