fix headers and check leaks