Refactor Message handling

- create class for file handling
- move code to class files