Added check for undefined currDoc variable