misc refactoring
added keyboardinterrupt handler