simplified macro by extracting to fns