refactoring and adding rescue block