Some refactoring in order to make the edit_mode work better with dynamically loaded elements.