Cleaning code and corrections