refactor removing of array elements