Some minor code optimization handling arrays added that makes code faster and uses less cpu.