Refactor the timeout code for secondary indexes