Adding state param
Fixed $log dep problem
Callback function is a standard function with added state verification
Functional version with callback function and state validation