Added smart DOM insert function