refine getNLines logic