Error control and clean-up