added subroutine for writing to 2d arrays