Added some verification of inputs
Improved input checking to cover more cases