validation and clean-up