Add test for managed client & add logging support. Fix several bugs.