last version. fixed some functions