Refactor beartrap.js