split out model.php code, added server side access