made the denormalize script a bit more robust