The apply fractions code bits extracted from grid merge repo