Fixed bug in Document constructor, added test