refactor using slices