It looks like duplication. consider generalizing this logic.