Improve error handling + cleanup