Some bug fixes for ArrayList