Fixed issue uncovered by Valgrind