Refactored.

Moved the code to check for documents inside helper methods.Started with
basic deletion of documents.