Fixed stack overflow bug