almost complete re-write of _code.js