got rid of the invalid reads in valgrind