Updated to handle negative number input and throw an exception for
negative input