refactor j* functions to use a factory, and improve documentation