twiddles and get rid of some malloc/free