create and cache a reusable function