add trim option to adjust how many tags at end of file are ignored