generic.js refactored untested