Works but with memory leaks.