Ported Manipulation code to manipulation.js