Ported layout from js version