Added callback function and fixed andrewkolesnikov's issue