fix the case where result is none
use lines.length instead