fix layout selection algorigthm