added a somewhat ugly implementation of callback function