Library: Improve document parsing