remove most malloc and free calls