Move some code to common.js