Cleanup work and error checking