Refactored arrayc function