Implementation of addDocument