Some code cleaning and speed increas