added some more safety checks