In lines() add zero length case and rearrange first loop to avoid duplicate cases. Reviewed-by: rriggs
Reviewed-by: alanb