refactored for flex number of children