fixed returned number of lines by allowing arbitrary calculation