Factor out implementation; apply it to createSnippet; fix othe rtests.