Fixed various memory leaks