logic cleanup, finished memory free'ing, valgrind is happy