Fixing unanticipated issues
Adding more sensible initial substitution and javascript restoration script