Memory leaks fix

- Memory leak fixes
- Test fixes