added database saving code