new version of the routines, now working for tiwa.