Refactoring: added login / logout - needs a fair amount of tidying up and consistency fixes