Working one

Rewrite of some functions.