fixed memory leak and added puzzle copy function