Fixed memory leaks

Fixed memory leaks