fixed a serious bug in usage of System.arraycopy, and changed the api