Added errorhandling for empty documents