Reverted [8568be1258] since this commit was not correct.
Reverted [9f0edc127f] since this commit was not correct.
Better fix than [9f0edc127f], now takes merged lines into account.