implement a callback to be called before loop