Check value is defined before checking length

Get's rid of undefined warning in some instances