Added except IndexError to provide slightly more informative error message.