working out memory leaks with valgrind. This code is passing check50 currently.