* Issue #347: Reduce duplicated code. * Issue #347: Replace array_* with regular loops for better perfomance.