More code cleaning and better documentation