Animated Align - based on existing keyframes...

I've got a small keyframe baking script,very similar to "Animated Align" by Jim Jagger.

The script is old and outdated, and at some point in time, I suspect because of changes to maxscript language changes in the past few years, the scripts ability to work broke down.

This script originally baked keys to the target object, but only onto the same frames that the source object had keyframes on, rather than the standard "every frame" or "every nth" frame options.

I'm hoping some kind soul might be willing to take a look a the old code that I had in this script and show me what to change to make it work again...

-- matchObj is the source object that is already animated
-- changeObj is the target object to bake keyframes onto
-- originall scripted so that the keyarray that gets created would work on a regular max object, but also on a character studio biped as well... (very important).

fn proKeyer matchObj changeObj =
set animate on
--gets the all keys through the main method, if there arnt any keys...
keyarray = matchObj.transform.controller.keys
if(keyarray.count == -1)do(
--try the other way
keyarray = matchObj[3][1].keys
--for each keyframe on Bip01 we get the time
for i = 1 to keyarray.count do(
--and goto that time and set the transform.
at time keyarray[i].time
tempobj = snapshot matchObj
tempobj.transform = matchObj.transform
changeObj.rotation = tempobj.rotation
delete tempobj
changeObj.transform = matchObj.transform

I've got other scripts that make use of the bottom half, that actually does the aligning part of the script... so I know that works. The first half is what must be broken... when it tries to define the keyarray.
(sorry for the formatting above too... for some reason it's not respecting my tabbed spacing when I paste in the code).

Many thanks in advance to all those maxscript contributors who are a ton smarter than this bloke..!