this now handles high throughput and always returns a single message at a time
Added comments.