Added functions and comments to viewer.js.