rework database functions