Refactored some longwinded code to be compact