More work on database logic