added error handling and fixed port