Move some generic functions to lib/generic.coffee