Code cleaning and tons of fixes