added some parameter safety checks