Reduced the need to a lengths function (which is a hack) and added more hacks.