Ed: test for list emptyness before use

thanks @skywave for the tips
Merge pull request #650 from antoine-de/fix_potential_crash

Ed: test for list emptyness before use