refactor viewcontroller and add comments