adding error validation and catching