packported fixes from ST3