copied lemming.js from master