Changed normalise username function
Added simple error checking on initial connection so that the script dies with a message instead of silently.
Few extra tweaks