fix tests and few bugs