Added try/catch for array index

re-formatted