added database writing