Transferred the logic in the index view to the controller