Fixed bug in document loading