cleanup and fixes of manipulation.js