Made the code a bit DRYer