move replaceData.js to more sensible location
fix #393 regression in magic mode
tidy up tests