Add error handling for list index errors