Implement _die function for early exiting
Fix memory leakages and double frees