Memory cleanup. Valgrind passes. Started implementing test case.