Added type checks in hopes to prevent errors