Removed many memory leaks