conform to spark style; rm redundant asserts; more unit tests added; use arraycopy instead of loop