revised code for views function, added test for no data scenarios