added errror checking