refactored valueBetween validation code