Small fixes to make it more robust