move line counting to only happen on error, instead of all the time