Check length to prevent IndexErrors