This function is a little long, perhaps you could move this loop out into a named function like "populateBars"?