Valgrind leak/access fixes