Split into smaller components. Added support for mongodb chat history save.