Database functionality put into functions