module: document the API and simplify the code

This does NOT change the module API/ABI in any way.
3 jobs for module-refactor
in 1 minute and 46 seconds and was queued for 0 seconds