Some fixes to improve performace