slightly improved function snippet