Fixing a bug where layout is triggered too early which can lead to strange behaviour