fixed bug to work with the passed dom to the function