added input checking