Minor refactoring and added shutdown operation