Fix two array related defects (MAGN-619, MAGN-337)

Test cases added as well.