Brought DB insertions out of main thread.