fix memory leaks in helper factory