moved database insert operations in new thread to improve performance