Fix length undefined error