Refactored out common code

Refactored out the common calls to logon and logoff.
The specific implementation is passed in via a block

Signed-off-by: Ippoippo <ippoippo-software@ippoippo-eco.com>