make factor module a bit faster
add module-based solution for #3 (though it's slower)