Complete rewrite to fix type and compile issues. Co-authored-by: null <4804959+fnvtk@users.noreply.github.com>