refractored and callback added