trimming lines; adding option to limit max lines; ignoring empty lines