fix bug with stackoverflow exception