first test passing in major refactor
All lite tests passing. Code backported from Perl.