messages refactor