some refactoring, maybe easier to make adaptive will test