manually maintain a stack to avoid StackOverFlow risk