merge detect, numerous imporovements