Fix out of range exception / syntax error