Added some conditionals and validation to logic.php.