Memory / Thread leaks fixed