Rearranged the code
DRY