factorizing code to read values