improve line search by applying regex only when necessary
add comments (and fix typo)