added better parameter checking