Factor out getMessages