fixed stack overflow bug