Fix freeze bug due to incorrect coding in callback

And also clean up compile warning for unused var.