Repaired the getNode() function to switch dynamically between documen and not