Simplifying sgr.js, using a function-factory