Added validation to make sure integers are in the correct range.