Made changes to improve handling of messages received asynchronously