Optimized a bit part of codes.