Fixed some issues from valgrind