Fixing double-free bug
Moving most includes into cpp to conform to coding standards