Refactor module `views`

Push redundant code in to class methods. Reformat code to make it look nicer,
and add some comments and whitespace to make it more understandable.