moved add views code to a reusable function