moved code to util.js