Reworked fix for #317 to prevent message loss