fixed major memory leak infinite loop issue