use arrays and array copy for efficiency