Fixed warnings and leaks