added back in error check and insert