Add connection badge, tidy up and refactor