added trap signals and clean function