added error checking for ws