Refactored dom document methods to return when error is caused.