Added some parameter checking