Add some exception handling + cleanup