Fixed leaks in code