fix to stack overflow bug