Write C version. Various corresponding improvements to original Perl.