wrapped callback in function, it fires too early