updated with error catching and stuff