Documentation and logic improvements