Add trap_exit and unlink in terminate to properly stop application