Added an catch to stop code out of bounds errors.