Refactor index view, move code to controller