Added input checking