Secon version:
- Now there is an additional parameter to add debug messages
- Improved the comments