Fixed a bug in the layout logic