fixed val[0] error