Updated comments
Re-add protocol setting
Add comments and tidy code