Logging improvements and initial tests