more optimisations: remove unused code, move function to value in Table, less and less call to the db