common.js refactored