Refactor views and fix views tests