Fixed some memory leaks for #124, but there are still more