Fixing some memleaks
Removed debug log_write()s