Improve automatic trimming of beforeValidate