Moved the main function to view