Full code review

See my comment bellow. Replace "a" by "line". Replace "cur" by a pair of variables with suggestive names.