Refactor the code in 'bem-tools.js'