Added error check and save actions