Refactor message sending

- add class to send messages
- move definitions to related files
- cleanup code
- add comments