Clean up primate.js and fixed a bug