add patches and patch logic by @hjunii