small optimizations to 'flatten'