some refactoring to boost::range