very hairy edit moving more functions to view