Added try block to avoid 'index out of range'