Added in a better check according to Mack's suggestion