add cli.php, separate controller into separate file
refactor to not use $GLOBALS