fixed stackoverflow in series and whilst