Database logic reworked.