Engine overhaul to use templates and modern c++ memory management