added errorchecking