merged memory-leak branch, seems works fine