Clean up the factorial code implementing better reverse loop, add some tests.