Should have fixed all restarting errors, moved to own function to not destroy all variables