Using compact and map for a more DRY solution