Refactoring to use array methods