diff --git a/package-lock.json b/package-lock.json
index a6ac8a9..cd52619 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
 {
   "name": "satyr",
-  "version": "0.2.0",
+  "version": "0.3.0",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
@@ -2370,6 +2370,14 @@
         "readable-stream": "^2.0.2"
       }
     },
+    "recursive-readdir": {
+      "version": "2.2.2",
+      "resolved": "https://registry.npmjs.org/recursive-readdir/-/recursive-readdir-2.2.2.tgz",
+      "integrity": "sha512-nRCcW9Sj7NuZwa2XvH9co8NPeXUBhZP7CRKJtU+cS6PW9FpCIFoI5ib0NT1ZrbNuPoRy0ylyCaUL8Gih4LSyFg==",
+      "requires": {
+        "minimatch": "3.0.4"
+      }
+    },
     "regex-not": {
       "version": "1.0.2",
       "resolved": "https://registry.npmjs.org/regex-not/-/regex-not-1.0.2.tgz",
diff --git a/package.json b/package.json
index b4a9377..c1fb672 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
 	"name": "satyr",
-	"version": "0.3.0",
+	"version": "0.3.1",
 	"description": "A livestreaming server.",
 	"license": "AGPL-3.0",
 	"author": "knotteye",
@@ -24,6 +24,7 @@
 		"mysql": "^2.17.1",
 		"node-media-server": ">=2.1.3 <3.0.0",
 		"nunjucks": "^3.2.0",
+		"recursive-readdir": "^2.2.2",
 		"socket.io": "^2.3.0",
 		"toml": "^3.0.0"
 	},
diff --git a/src/cleanup.ts b/src/cleanup.ts
new file mode 100644
index 0000000..7fe1fa4
--- /dev/null
+++ b/src/cleanup.ts
@@ -0,0 +1,23 @@
+import * as db from "./database";
+import * as read from "recursive-readdir";
+import * as fs from "fs";
+
+async function init(siteDir: string) {
+    //If satyr is restarted in the middle of a stream
+    //it causes problems
+    //Live flags in the database stay live
+    await db.query('update user_meta set live=false');
+    //and stray m3u8 files will play the last
+    //few seconds of a stream back
+    try {
+        var files = await read(siteDir+'/live', ['!*.m3u8']);
+    }
+    catch (error) {}
+    if(files === undefined || files.length == 0) return;
+    for(let i=0;i<files.length;i++){
+        fs.unlinkSync(files[i]);
+    }
+    return;
+}
+
+export { init };
\ No newline at end of file
diff --git a/src/controller.ts b/src/controller.ts
index 1844aa3..461eb8a 100644
--- a/src/controller.ts
+++ b/src/controller.ts
@@ -2,9 +2,10 @@ import * as mediaserver from "./server";
 import * as db from "./database";
 import * as api from "./api";
 import * as http from "./http";
+import * as cleanup from "./cleanup"
 import * as config from "config";
 
-function run(): void{
+async function run() {
 	const dbcfg: object = config.database;
 	const bcryptcfg: object = config.bcrypt;
 	const satyr: object = {
@@ -52,9 +53,10 @@ function run(): void{
 		}
 		
 	};
+	db.init(dbcfg, bcryptcfg);
+	await cleanup.init(config.server.http.directory);
 	api.init(satyr);
 	http.init(satyr, config.server.http.port);
-	db.init(dbcfg, bcryptcfg);
 	mediaserver.init(nms, satyr);
 }
 run();