Some code cleaning and some tests