Some cleaning and fix for performance issues