Fix for some memory leaks
Cosmetic updates
Fix for wrong errors logging