Everything works, now to plug a memory leak