clean up code, fix possible goroutine cpu hog