Fix range exception due to nextElement being nil
Merge pull request #3 from Alydyn/master

Fix range exception due to nextElement being nil