Basic error handling and clean-up