fixed Memory Leak , improved memory allocations