patch logic