move common function to util.js. change args from code to character at leap