okay, but is there any code lines we can remove? The function maintains a few complicated status that may not necessary here.