added a generic function for counting elements and size of media items