Moved working code to index.php