updated to account for no-block scope in javascript, created new callback function to lock in orig value or i in func.