Added emptiness constraints

you'll need to check value is defined before accessing length