change to response to callback function, named onsuccess
added function check to avoid undefined