Changed syntax and fixed out-of-range bug