Improved rebuild.js