fixing scoping issue in callbacks