This code adds additional headers into the tableview, instead of hiding empty headers. Basically every time we call "index.add(i)", we're adding a row into the tableview, whether it is a header or an actually row. 
Here we should have checks to see if the header is empty. If it is, don't add it. You can check for empty header by looking at next values: i.e if item(i) is a header and item(i+1) is a footer or header, we know that it's item(i) is an empty header. 
Note that this is just one condition for empty headers. The goal here is to HIDE all empty headers AND footers.