Added error checking

Error checking added for document load functions.