new version with callback support