Added assertions and checks for empty lists.
Fixes #59