some unit tests and code cleaning