Update IndexController.php

alteration: reorganization of the code