Save to database function almost implemented. 
Needs testing!