based on 549b7e3e11 with some parts removed, and some parts backported from the latest commit
549b7e3e11
Co-authored-by: Zypherift <regokoppany@gmail.com>