added more parameter checking code