Added typing for new documents and fixed sorting