improved code for handling callbacks across post message