Refactor JS to separate DTD related code into own JS file