Writing to SQLite database now happens in seperate thread

Signed-off-by: Lucas Arnström <lucasarnstrom@gmail.com>