Jhbate/cleanup

@kentquirk - some more cleanup while i was looking at the logout and message issues. I just added common code for the puts and post calls (as we already had for get). Also in the tests on the after I now do a logout.
There is a lot of defaulting going on around the codes object; it can be missing, it can contain a function or something that isn't a function...can you please add some documentation around what it's expected to contain?