Remove unnecessary code
Remove event listeners when element is removed from parent
Avoid going past bounds by checking length of string first when checking for .rml extension