Refactor controller and index file