Improved input checking.