more restructuring
fixed database handles