moved allocs around for mem efficiency