replaced the check of port number with a helper method.