Applying valgrind sugestions of memory leaks.