BUG: Fixed memory leaks