Updated to include setAttribute with added overwrite flag.