Added checking for values in range