Fix bugs in arraycopy