Refactor sensorsubmit.php into functions