small refactoring on arrays and better array updates