Refactored some code in index.php