implemented signal sigterm; refactoring
use signal sigterm
output; refactoring