Refactor to fix the callback bug
Fixed variable reference bug