cleaning, improvements and bug fixes

cleaning, improvements and bug fixes