Fixed undefined var.
Fixed bound check.