Added guards to prevent accessing arrays when there isn't any data.
Resolves #52