CommandSession refactored to avoid deserialization problems