extract functions into utils.js and add unit tests for these