Prevent index out of range. Fixes #7.