added error checks to ensure the inputed variables actually are in the range we require