moved messages logic to its own module