refactor code into classes and add toggle view function.