Flush packets before setting protocol (fixes #91).
Minor cleanup.