Changed manual selection of LAST_INSERT_ID() to tntdb method,
repaired all the logging code