consolidate some code in ide.js and fix a minor bug