fixed calc of num_lines. added unit tests.