added database write functionality