waay better frame allocation code