refactor: cleanup buffered messages handling code