renaming fn and removed duplicated code in callback fn