Simplified flexbox algorithm

Moved here.