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

...osed).

Id of connection should be incremeneted.