errors and cleanup