Subtle bug on very short sections (1 line).
Simplified the code.