made layout algorithm more efficient by doing less