added if else loop to view