updated reference implementation