refactoring using arrays