added comment
check if target is defined
fixed 'undefined' bug