Fix debug & Allow to enable proxy & Fix memleak (open files should be cl...

Some changes:
* Rewrite debug log
* Allow to enable proxy
* Fix memleak (open files should be closed).
* Id of connection should be incremeneted up from 1