Some cleanup and custom exception.