Change messages to a ref, add handlers for async persistence