cleaned up main.php code a bit