refactored array algorithms