fixed cleanup method to accumulate errors and print them at the end