Added input value checks to prevent invalid values