Adding logging and correcting logic error in auto trim.