made the whole thing a bit more robust