fixing a bug with array copy