added ability to use custom callback functions, updated example