Added checking for nonexistant target element (this is undefined).