almost have memory leaks fixed