Clean up code and free malloced memory. Ready for integration into Limelight-Common-C (fingers crossed)