Fix incorrect end length calculation. Closes #161 Thanks BStramke!