Remove python dependency and use manual memory management to get rid of memory leak