Refactored some code in the views