Better logging and some exception handling.