Speedup restore levels

1000x speed increase in numeric_to_factor by porting to C