removed superfluous flattens, made generated code look almost like what hand crafted code would look like