Refactor Flask views