fixed a long-standing memory bug; thanks valgrind