Fixing memory leaks but still invalid access in valgrind
Fixing memory access issues, now test number two working fine with valgrind