refact view logic