fix and adapt to upstream