DRY up the code a bit