refactored server and chat

externalized chat
refactor some code inside srv and fix fantom bug