refactored code
fix error in the view