fixed bug in layout script that prevented last item being placed if it didn't fit on the row