How to implement a callback function