Better error handling, cleanup.