validation and cleanup