Fixed tests and cleaning some functions