Some code optimizations
Performance gain are around 50 percent