Move PHP logic to logic.php