- improve robustness against invalid input
- use lassign instead of "foreach ... break" idiom
- use "in" operator instead of lsearch