Well I didn't set out to rewrite this...  I'll try to fix some of the variable names