Restored headers
Fixed memory leaks