Hotfix to message queue

Avoid NoSuchElementException checking availability of next element