Added port option and error handling