got rid of most memory leaks, still some left I think...