various improvements

- added external config
- added mysql connection error handling and reconnect loop
- added a bit of comments