added some protection to my functions