Changed sprintf to snprintf & added database mutex