Trying to fix Element is no longer attached to the DOM error