what is the reason of double passing through array(line 15 and 18)?
is there possibility to merge both cycles into single one?