refactor, add some code
Ah. I got lazy and added an extra asterisk.
define another one to match the reference implementation
looks semi-sane