refactored and catched exceptions