Add debug mode and logging files
Add exception logging and retry on error