improved document parsing