Using array lists instead of arrays. Corrected some mistakes. Need to update tests.