changed formatting and output. need to recheck with valgrind