Fixed all memory leaks, added hack to get memory working