refactored duplicating of HTML structure to $.detach to context