Removed unused variable
Fixed memory leaks
Added valgrind check to test suite