added save to database function