Correctly remove points at the end of a line