Small refactor in common.js
Small tweaks to fix #1 (in progress)