identified and circumvented bug in flatten