Fixing some memory leak - more test required. Valgrind is the next step