Fix array range error, and syntax error