Much faster (walks through document only once), wrapped in function to prevent polluting global namespace.