added comments on mainjs and demoView; refactored code