Fixes Memory Leaks reported by Valgrind