improve view function